#version 450 core

layout(binding = 0) uniform samplerCube skyboxTex;
layout(binding = 2) uniform sampler2D tex;

layout(std140, binding = 0) uniform PerDraw
{
    mat4 viewMatrix;
    mat4 projMatrix;
    vec3 cameraPos;
} perDraw;

in Varyings
{
    vec3 positionWS;
    vec3 normalWS;
    vec2 uv;
} i;

out vec4 fragColor;

void main()
{
    vec3 V = normalize(perDraw.cameraPos - i.positionWS);
    vec3 N = normalize(i.normalWS);

    // 计算反射向量
    vec3 R = reflect(-V, N);
    fragColor = vec4(texture(skyboxTex, R).rgb, 1.0);

    // 计算折射向量
//    float ratio = 1.0 / 1.52;
//    vec3 R = refract(-V, N, ratio);
//    fragColor = vec4(texture(skyboxTex, R).rgb, 1.0);
}
